﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//------------//
using QLKTX1._0.DTO;
using QLKTX1._0.DB;
using System.Data.SqlClient;
using System.Data;

namespace QLKTX1._0.DAO
{
    class KhuDAO
    {
        public static List<KhuDTO> dsKhu()
        {
            List<KhuDTO> dsKhu = new List<KhuDTO>();

            ConnectDB con = new ConnectDB();

            DataTable dt = con.getDataTable("SELECT * FROM Khu");

        

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                KhuDTO khu = new KhuDTO();

                khu.MaKhu = dt.Rows[i]["maKhu"].ToString();

                khu.TenKhu = dt.Rows[i]["tenKhu"].ToString();

               // KhuDTO k = new KhuDTO(dt.Rows[i]["maKhu"].ToString(), dt.Rows[i]["tenKhu"].ToString());

                dsKhu.Add(khu);
            }

            return dsKhu;

        }
        // KhuDAO.themKhu(); 
        public static bool themKhu(KhuDTO khu){

            ConnectDB con = new ConnectDB();// dung DB

            return con.executeQuery("INSERT INTO Khu(maKhu,tenKhu) VALUES('"+khu.MaKhu+"',N'"+khu.TenKhu+"')");

        }
        //Ham delete
        public static bool xoaKhu(KhuDTO khu)
        {
            ConnectDB con = new ConnectDB();

            return con.executeQuery("DELETE FROM Khu WHERE maKhu='" + khu.MaKhu + "'");
        }
        //ham update
        public static bool capNhatKhu(KhuDTO khu)
        {
            ConnectDB con = new ConnectDB();

            return con.executeQuery("UPDATE Khu set tenKhu=N'"+khu.TenKhu+"' WHERE maKhu='" + khu.MaKhu + "'");
        }
    }
}
